package com.translate.web.api.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.param.impl.IdPageParam;
import com.translate.vo.ManuscriptVO;
import com.response.vo.ResponseModel;
import com.controller.base.AbstractCommonController;
import com.jwt.IJwtUtil;
import com.page.PageResponseData;
import com.translate.web.param.ManuscriptUpdateParam;
import com.translate.web.param.ManuscriptAddParam;
import com.translate.web.param.contract.IManuscriptAddParam;
import com.translate.entity.Manuscript;
import com.translate.web.service.IManuscriptService;
import com.basic.service.contract.IBaseService;
@RestController
@RequestMapping("manuscript")public class ManuscriptController extends AbstractCommonController<Manuscript, IdPageParam> { private IManuscriptService service;
private IJwtUtil jwtUtil;
@Autowired
 public void setJwtUtil(IJwtUtil jwtUtil) {this.jwtUtil = jwtUtil;}
public ManuscriptController(IManuscriptService service) {
this.service = service;
}
protected  long setCreateInfo(IManuscriptAddParam param,HttpServletRequest httpServletRequest) {
		long userId = this.getUserId(httpServletRequest);
//		param.setCreateUserId((int) userId);
		return userId;
	}
protected long getUserId(HttpServletRequest httpServletRequest) {
		return jwtUtil.getId(httpServletRequest.getHeader(jwtUtil.getJwtConfig().getHeader()));
	}
/**
 * 添加
* 
 * @param <V>
 * @param param
 * @return
*/	@PostMapping("/add")
	public ResponseModel<Integer> insert(@RequestBody @Validated ManuscriptAddParam param, HttpServletRequest httpServletRequest) {
 setCreateInfo(param, httpServletRequest);
int id = this.service.parseInsert(param, Manuscript.class);

return ResponseModel.<Integer>success(id);
}@Override
protected IBaseService<Manuscript>getBaseService() {
return this.service;
	}/**
* 添加
* 
 * @param <V>
 * @param param
	 * @return
	 */
	@PostMapping("/update")
	public ResponseModel<Integer> update(@Validated @RequestBody ManuscriptUpdateParam param, HttpServletRequest httpServletRequest) {
int res = this.service.parseUpdate(param, Manuscript.class);
return ResponseModel.<Integer>success(res);
}
protected <VO> Class<VO> getTarget() {
return  (Class<VO>)ManuscriptVO.class;}
}